package com.hmall.trade.listener;

import com.hmall.common.constants.MqConstants;
import com.hmall.trade.service.IOrderService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

/**
 * TODO
 *
 * @Author mr.wu
 * @Data #{DATE} #{TIME}
 */
@Component
@Slf4j
@RequiredArgsConstructor
public class PayStatusListener {

    private final IOrderService orderService;

    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = MqConstants.PAY_SUCCESS_QUEUE),
            exchange = @Exchange(name = MqConstants.PAY_EXCHANGE_NAME,type = "direct"),
            key = MqConstants.PAY_SUCCESS_KEY
    ))
    public void markOrderPaySuccess(Long orderId) {
        orderService.markOrderPaySuccess(orderId);
        log.info("[更新订单-修改状态]消费者根据id修改订单状态，订单id：{}",orderId);
    }
}
